﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ThinhTien.Models;
using System.Web.Routing;

namespace ThinhTien.Admin.Attributes
{
    public class AuthorizeUserAttribute : AuthorizeAttribute
    {
        private UserInfo userInfo = null;
        AuthorizationContext filterContext;
        protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
        {
            this.filterContext = filterContext;
            userInfo = filterContext.HttpContext.Session["UserInfo"] as UserInfo;
            if (userInfo == null)
            {
                filterContext.Result = new RedirectToRouteResult(
                            new RouteValueDictionary(
                                new
                                {
                                    controller = "Account",
                                    action = "Login"
                                })
                            );
            }
            

            //base.HandleUnauthorizedRequest(filterContext);
        }


        private void GotoError(string url)
        {
            HttpContext.Current.Session["URL"] = url;
            filterContext.Result = new RedirectToRouteResult(
                            new RouteValueDictionary(
                                new
                                {
                                    controller = "Error",
                                    action = "Index"
                                })
                            );
        }
    }

}